<template>
  <div class="showBlogs">
    <h1>博客纵览</h1>
    <input type="text" placeholder="搜索" v-model="serch">
    <div v-for="blog in filteredBlogs" class="single-blog" :key="blog.title">
      <router-link :to="'/blog/' + blog.id">
        <h2 v-rainbow class="title">{{blog.title}}</h2>
      </router-link>
      <article class="blog-content">{{blog.content | snippet}}</article>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
import axios from "axios";
export default {
  data() {
    return {
      blogs: [],
      serch: ""
    };
  },
  computed: {
    filteredBlogs() {
      return this.blogs.filter(blog => blog.title.match(this.serch));
    }
  },
  components: {},

  created() {
    axios
      .get("https://wd9328603459zdqdne.wilddogio.com/blog.json")
      .then(res => {
        //   this.blogs = res.data.slice(0, 10);
        let data = res.data;
        let blogsArray = [];
        for (const key in data) {
          data[key].id = key;
          blogsArray.push(data[key]);
          //   console.log(data[key]);
        }
        this.blogs = blogsArray;
        // console.log(this.blogs);
      });
  }
};
</script>

<style scoped>
.single-blog {
  border-radius: 8px;
  /* background-color: #eee; */
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 1px 1px 4px 1px #ddd;
}
.single-blog:hover {
  box-shadow: 1px 4px 8px #999;
}

.showBlogs {
  /* background-color: #eee; */
  max-width: 800px;
  font-size: 14px;
  margin: 0 auto;
}
.title {
  font-size: 30px;
  line-height: 30px;
}
input[type="text"] {
  padding: 8px;
  width: 100%;
  box-sizing: border-box;
  margin-bottom: 40px;
}
a {
  text-decoration: none;
  color: #444;
}
</style>
